package com.itcast.kotlin_two.kotlin

fun main() {
    val person = Person("张三", 18)
    println(person.name)
    println(person.age)
    val person3 = person2("李四", 80)
    person3.intro()
    val person2 = person2("李四", -20)
    person2.intro()

}

class Person constructor(var name: String, var age: Int) {
    init {
        //    初始化验证
        require(name.isNotEmpty()) { "姓名不能为空" }
        require(age > 0) { "年龄不能小于0" }
    }

}

// class Person constructor(name: String, age: Int) {
//     val name: String = name
//     val age: Int = age
// }
class person2(var name: String, var age: Int) {
    init {
        // 初始化验证
        require(name.isNotEmpty()) { "姓名不能为空" }
        require(age > 0) { "年龄不能小于0" }
    }

    fun intro() {
        println("name: $name, age: $age")
    }
}


